package banner

import (
	"context"
	"errors"
	"group-buy/group_buy/internal/models"

	"group-buy/group_buy/internal/svc"
	"group-buy/group_buy/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetBannerLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGetBannerLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetBannerLogic {
	return &GetBannerLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GetBannerLogic) GetBanner(req *types.FormIdReq) (resp *types.Banner, err error) {
	m := &models.Banner{Id: req.Id}
	get, err := l.svcCtx.Engine.Get(m)
	if err != nil {
		return nil, err
	}
	if !get {
		return nil, errors.New("配置不存在")
	}
	return &types.Banner{
		Id:    m.Id,
		Title: m.Title,
		Path:  m.Path,
		Url:   m.Url,
		Sort:  m.Sort,
	}, nil

}
